package com.ljz.controller;

import com.ljz.dao.MerchantRepository;
import com.ljz.entity.Merchant;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * Created by jiazhang on 2017/4/12.
 */

@RestController
public class MerchantController {

    @Autowired
    private MerchantRepository merchantRepository;

    /**
     * 查询所有的信息
     * @return
     */
    @GetMapping(value = "/merchant")
    private List<Merchant> merchantList() {
        return merchantRepository.findAll();
    }

    /**
     * 添加信息
     * @param mname
     * @param mphone
     * @param maddress
     * @return
     */
    @PostMapping(value = "/merchant")
    public Merchant merchantAdd(@RequestParam("mname") String mname,
                                @RequestParam("mphone") String mphone,
                                @RequestParam("maddress") String maddress) {
        Merchant merchant = new Merchant();
        merchant.setMaddress(maddress);
        merchant.setMname(mname);
        merchant.setMphone(mphone);

        return merchantRepository.save(merchant);
    }
}
